#copy all files in the folder (including all sub-folders recursively) into another folder

#os.listdir(dir1), the variable for keeping all data
#create dir2
#os.path.join each basename and dirname
#isfile > copy file
#is dir > recursion

'''
import os

def mycopyfile(file1,file2):
    f1 = open(file1,"rb")
    f2 = open(file2,"wb")
    content = f1.readline()
    while len(content)>0:
        f2.write(content)
        content=f1.readline()
    f1.close()
    f2.close()

def mycopydir(dir1,dir2):
    dir_list = os.listdir(dir1)
    os.mkdir(dir2)

    for f in dir_list:
        file1 = os.path.join(dir1,f)
        file2 = os.path.join(dir2,f)

        if os.path.isfile(file1):
            mycopyfile(file1,file2)
            print("Files have been successfully copied.")
        elif os.path.isdir(file1):
            mycopydir(file1,file2)
            print("Dirs have been successfully copied.")
 '''           
            

#mycopyfile("C:\\Users\\Johnny-C.Y\\Desktop\\Py\\save\\a.txt","C:\\Users\\Johnny-C.Y\\Desktop\\Py\\save\\b.txt")

#mycopydir("C:\\Users\\Johnny-C.Y\\Desktop\\Py\\save\\aa","C:\\Users\\Johnny-C.Y\\Desktop\Py\\save\\bb")

#to get folders size : os.path.getsize()

import os

def getFolderSize(F_Path):
    dir_list = os.listdir(F_Path)
    global SUM   # import a global variable
    for f in dir_list:
        file = os.path.join(F_Path,f)
        if os.path.isfile(file):
            SUM += os.path.getsize(file) # to save each size data without being reset
        if os.path.isdir(file):
            getFolderSize(file) #use recursion itself

SUM = 0
getFolderSize("C:\\Users\\Johnny-C.Y\\Desktop\\Py\\save\\aa")  #put any folder's path to get it's size of all
print(SUM) #














